package org.teamh.gui.engine.model;

import org.lwjgl.opengl.GL11;

/**
 * Represents a mesh of an obj model. 
 * @author richard
 *
 */
public class OBJMesh extends Mesh {

	public OBJMesh(int[] buffers, int numVertices) {
		super(buffers, numVertices);
	}

	@Override
	public void render() {
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTexture());
		
		if(getMaterial() != null) {
//			getMaterial().bind();
		}
		
		GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
		GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
		GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
		
		// Vertices
	    VBO.glBindBuffer(getBuffers()[0]);
	    GL11.glVertexPointer(3, GL11.GL_FLOAT,0,  0);
	    
	    // Normale
	    VBO.glBindBuffer(getBuffers()[1]);
	    GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0);
		
	    // Textur-Koordinaten
	    VBO.glBindBuffer(getBuffers()[2]);
	    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
		
	    //Zeichnen
	    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, getNumVertices());
		
		// aufraeumen
		VBO.glBindBuffer(0);
		VBO.glBindBuffer(0);
		VBO.glBindBuffer(0);
		
		GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
		GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
		GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
	}

}
